#include "StdAfx.h"
#include "GlobalParas.h"

#define FILTER_DIVIDE ';'
CRITICAL_SECTION csProcessFilter;
CRITICAL_SECTION csTextFilter;
vector<CString> m_filterProcess;
vector<CString> m_filterText;

CGlobalParas::CGlobalParas(void)
{
	InitializeCriticalSection(&csProcessFilter);
	InitializeCriticalSection(&csTextFilter);
}

CGlobalParas::~CGlobalParas(void)
{
	DeleteCriticalSection(&csProcessFilter);
	DeleteCriticalSection(&csTextFilter);
}


void CGlobalParas::SetProcessFilter(CString processFilter)
{
	m_filterProcess.clear();
	if(processFilter.GetLength()>0)
	{
		int nPos = processFilter.Find(FILTER_DIVIDE);
		if(nPos<0)
		{
			m_filterProcess.push_back(processFilter);
		}
		else
		{
			//EnterCriticalSection(&csProcessFilter);
			while(nPos>=0)
			{
				CString temp = processFilter.Left(nPos);
				if(temp.GetLength()>0)m_filterProcess.push_back(temp);
				processFilter = processFilter.Right(processFilter.GetLength()-nPos-1);
				nPos = processFilter.Find(FILTER_DIVIDE);
			}
			//LeaveCriticalSection(&csProcessFilter);
		}
	}
}

void CGlobalParas::SetTextFilter(CString textFilter)
{
	m_filterProcess.clear();
	if(textFilter.GetLength()>0)
	{
		int nPos = textFilter.Find(FILTER_DIVIDE);
		if(nPos<0)
		{
			m_filterText.push_back(textFilter);
		}
		else
		{
			//EnterCriticalSection(&csTextFilter);
			while(nPos>=0)
			{
				CString temp = textFilter.Left(nPos);
				if(temp.GetLength()>0)m_filterText.push_back(temp);
				textFilter = textFilter.Right(textFilter.GetLength()-nPos-1);
				nPos = textFilter.Find(FILTER_DIVIDE);
			}
			//LeaveCriticalSection(&csTextFilter);
		}
	}
}

BOOL CGlobalParas::IsProcessFilter(CString text)
{
	if(m_filterProcess.size()<=0)
	{
		return TRUE;
	}
	if(text.GetLength()>0)
	{
		for(int i=0;i<m_filterProcess.size(); i++)
		{
			if(text.Find(m_filterProcess[i] >= 0))
			{
				return TRUE;
			}
		}
	}
	return FALSE;
}

BOOL CGlobalParas::IsTextFilter(CString text)
{
	if(m_filterText.size()<=0)
	{
		return TRUE;
	}
	if(text.GetLength()>0)
	{
		for(int i=0;i<m_filterText.size(); i++)
		{
			if(text.Find(m_filterText[i] >= 0))
			{
				return TRUE;
			}
		}
	}
	return FALSE;
}